package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import util.GetTime;

public class DataBoardDAO {
	public static void main(String[] args){
		 
		 DataBoardDAO dao = new DataBoardDAO();
//		 DataBoard db = new DataBoard();
//		 db.setDbno(8);
//		 db.setCono(7);
//		 db.setDbname("일본어강좌");
//		 int num = dao.getNextNum(db);
//		 System.out.println("test!!!!= "+num);
		 
		 Vector a = dao.getSavedFileNames(7,"프로그램강좌");
		 
		 for(int i=0;i<a.size();i++){
			 System.out.println(a.get(i));
		 }
		 
		 //Vector<DataBoard> v = dao.getTopList(db);
		 //System.out.println(v.size());
//		 for(int i =0; i<v.size();i++){
//		 DataBoard dboard = v.get(i);
//		 System.out.println(dboard.getDbtitle());
//		 }
	}	

	// 자료실 글 등록
	public boolean insert(DataBoard db) {
		System.out.println("dbcontent = "+db.getDbcontent());
		Connection conn = ConnectionManager.getConnection();
		String sql = "insert into databoard(dbno,cono,dbname,mid,dbtitle,dbdate,dbcontent,dbcounter,dbsfn,dbofn,dbfsize,dbftype)"
				+ " values(DATASEQ.NEXTVAL,?,?,?,?,?,?,0,?,?,?,?)";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, db.getCono());
			ps.setString(2, db.getDbname());
			ps.setString(3, db.getMid());
			ps.setString(4, db.getDbtitle());
			ps.setTimestamp(5, GetTime.nowTime);
			ps.setString(6, db.getDbcontent());
			ps.setString(7, db.getDbsfn());
			ps.setString(8, db.getDbofn());
			ps.setInt(9, db.getDbfsize());
			ps.setString(10, db.getDbftype());

			ps.executeUpdate();

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}

	//특정 커뮤니티  자료실  삭제
	public boolean delete(int cono){
		String sql1 = "delete from datacomment where dbno in (select dbno from databoard where cono=?)";
		String sql2 = "delete from databoard where cono=?";
	
		
		Connection conn = ConnectionManager.getConnection();
		try{
			PreparedStatement pstmt1 = conn.prepareStatement(sql1);
			PreparedStatement pstmt2 = conn.prepareStatement(sql2);
			
			pstmt1.setInt(1, cono);
			
			pstmt2.setInt(1, cono);
			
			pstmt1.executeUpdate();
			pstmt2.executeUpdate();
			return true;
		} catch(Exception e){
			e.printStackTrace();
			return false;
		} finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
	}
	
	public boolean delete(int cono , String mid) {
		Connection conn = ConnectionManager.getConnection();
		try {
			
			Statement st = conn.createStatement();
			st.executeUpdate("delete from databoard where cono=" + cono + " and mid='"+mid+"'");
			return true;
			
		} catch (Exception e) {
	
			e.printStackTrace();
			return false;
			
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}
	

	// 자료실 글 삭제
	public boolean delete(DataBoard db) {
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			st
					.executeUpdate("delete from databoard where dbno="
							+ db.getDbno());

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}

	// 자료실 제목, 내용 수정
	public boolean updateContent(DataBoard db) {
		Connection conn = ConnectionManager.getConnection();
		String sql = "update databoard set dbtitle=?,dbcontent=? where dbno=";
		try {
			PreparedStatement ps = conn.prepareStatement(sql + db.getDbno());
			ps.setString(1, db.getDbtitle());
			ps.setString(2, db.getDbcontent());
			ps.executeUpdate();

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}

	// 자료실 자료 수정
	public boolean updateFile(DataBoard db) {

		Connection conn = ConnectionManager.getConnection();
		String sql = "update databoard set dbsfn=?,dbofn=?,dbfsize=?,dbftype=? where dbno=";
		try {
			PreparedStatement pst = conn.prepareStatement(sql + db.getDbno());
			pst.setString(1, db.getDbsfn());
			pst.setString(2, db.getDbofn());
			pst.setInt(3, db.getDbfsize());
			pst.setString(4, db.getDbftype());
			pst.executeUpdate();

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}

	// 특정 자료실 전체 글 수
	public int getTotalRows(DataBoard db) {
		int totalRows = 0;
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st
					.executeQuery("select count(*) from databoard where cono="
							+ db.getCono() + " and dbname='" + db.getDbname()
							+ "'");
			rs.next();
			totalRows = rs.getInt(1);
			rs.close();
			st.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return totalRows;
	}
	
	//아이디로 검색했을 경우 총 행수 
	public static int getTotalRowsByMid(String mid, int cono, String dbname){
		String sql = "select count(*) from databoard where cono=? and dbname=? and mid=?"; 
		Connection conn = ConnectionManager.getConnection();
		int result = 0;
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setLong(1, cono);
			pstmt.setString(2, dbname);
			pstmt.setString(3, mid);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				result = rs.getInt(1);
			}			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return result;
	}
	
	//제목으로 검색했을 경우 총 행 수 
	public static int getTotalRowsByTitle(String dbtitle, int cono, String dbname){
		String sql = "select count(*) from databoard where cono=? and dbname=? and dbtitle like '%"+dbtitle+"%'"; 
		Connection conn = ConnectionManager.getConnection();
		int result = 0;
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setLong(1, cono);
			pstmt.setString(2, dbname);
			
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				result = rs.getInt(1);
			}			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return result;
	}
		
	//조성일
	public int getDbNo(int cono , String mid) {
		int result = 0;
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery("select dbno from databoard where cono="+cono+" and mid='" +mid+ "'");
			rs.next();
			result = rs.getInt(1);
			rs.close();
			st.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return result;
	}

	// 자료실 전체 글 수 
	public int getTotalRows() {
		int totalRows = 0;
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery("select count(*) from databoard");
			
			rs.next();
			totalRows = rs.getInt(1);
			rs.close();
			st.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return totalRows;
	}

	/**
	 * 조성일 만듬 커뮤니티별 총 레코드 수 취득
	 */
	public int getTotalRows(int cono) {
		int totalRows = 0;
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st
					.executeQuery("select count(*) from databoard where cono="
							+ cono);
			rs.next();
			totalRows = rs.getInt(1);
			rs.close();
			st.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return totalRows;
	}

	// 자료실 글 보기
	public DataBoard getDataBoard(int dbno) {
		Connection conn = ConnectionManager.getConnection();
		DataCommentDAO d = new DataCommentDAO();
		DataBoard dboard = null;
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st
					.executeQuery("select * from databoard where dbno=" + dbno);
			if (rs.next()) {
				dboard = new DataBoard();
				dboard.setDbno(rs.getInt(1));
				dboard.setCono(rs.getInt(2));
				dboard.setDbname(rs.getString(3));
				dboard.setMid(rs.getString(4));
				dboard.setDbtitle(rs.getString(5));
				dboard.setDbdate(rs.getString(6));
				dboard.setDbcontent(rs.getString(7));
				dboard.setDbcounter(rs.getInt(8));
				dboard.setDbsfn(rs.getString(9));
				dboard.setDbofn(rs.getString(10));
				dboard.setDbfsize(rs.getInt(11));
				dboard.setDbftype(rs.getString(12));
				dboard.setCommentRows(d.getCommentRows(dboard.getDbno()));
			}
			rs.close();
			st.close();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return dboard;
	}
	
	// 자료실 리스트 보기
	public Vector<DataBoard> getDataBoardListPage(DataBoard db,
			int currentPage, int rowsPerPage) {
		
		long startindex = (currentPage - 1) * rowsPerPage + 1;//1
	    long endindex = currentPage * rowsPerPage;//8
	    int rownum = getTotalRows(db) + 1;//18
	    //@@
	    int index = 0; 
		
		Vector<DataBoard> list = new Vector<DataBoard>();
		DataCommentDAO d = new DataCommentDAO();

		Connection conn = ConnectionManager.getConnection();
		/*@@ String sql = "select data.*, (@rownum:=@rownum+1) num from (select *, (@rownum:=0) rnum from databoard where cono="
				+ db.getCono()
				+ " and dbname='"
				+ db.getDbname()
				+ "')data order by num desc limit "
				+ rowsPerPage
				* (currentPage - 1) + "," + rowsPerPage;*/
		String sql = "select * from databoard where dbname='"+db.getDbname()+"' order by dbno desc";
		try {
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			while (rs.next()) {
				
			
				 index += 1;  //@@ 모든 행에 인덱스번호 부여 1~끝까지
			     rownum -= 1;
			     if(index >= startindex && index <= endindex){
				
				DataBoard dboard = new DataBoard();
				dboard.setDbno(rs.getInt(1));
				dboard.setCono(rs.getInt(2));
				dboard.setDbname(rs.getString(3));
				dboard.setMid(rs.getString(4));
				dboard.setDbtitle(rs.getString(5));
				dboard.setDbdate(rs.getString(6));
				dboard.setDbcontent(rs.getString(7));
				dboard.setDbcounter(rs.getInt(8));
				dboard.setDbsfn(rs.getString(9));
				dboard.setDbofn(rs.getString(10));
				dboard.setDbfsize(rs.getInt(11));
				dboard.setDbftype(rs.getString(12));
				dboard.setRownum(rownum);
				//@@ dboard.setRownum(rs.getInt(14));

				dboard.setCommentRows(d.getCommentRows(dboard.getDbno()));

				list.add(dboard);
			     }
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null)
				try {
					conn.close();
				} catch (Exception e) {
				}
		}
		return list;
	}

	// 특정 목록 검색 
	//## sql1 = id 검색 sql2 = 제목검색 sql3 = 내용검색
	//## 소스상으로는 내용 검색까지 할수 있게 해놨지만 게시판에는 내용 검색하는 것이 제외됨
	
	public Vector<DataBoard> search(DataBoard fb, int currentPage,
			int rowsPerPage) {
		
		
	    int rownum = (int)this.getTotalRowsByMid(fb.getSearchData(), fb.getCono(), fb.getDbname()) + 1;
	    //## 검색데이터&cono&dbname으로 구별하여 총 열의개수를 구함
	    //@@
	     
	    
		Vector list = new Vector();
		DataCommentDAO d = new DataCommentDAO();
		Connection conn = ConnectionManager.getConnection();
		String sql1, sql2, sql3 = null;
		ResultSet rs = null;
		try {
			Statement st = conn.createStatement();
			if (fb.getSearchList().equals("mid")) {
				/*@@ sql1 = "select data.*, (@rownum:=@rownum+1) num from (select *, (@rownum:=0) rnum from databoard where mid='"
						+ fb.getSearchData()
						+ "' and cono="
						+ fb.getCono()
						+ " and dbname='"
						+ fb.getDbname()
						+ "')data order by num desc limit "
						+ rowsPerPage
						* (currentPage - 1) + "," + rowsPerPage;*/
				//##
				sql1 = "select * from databoard where mid='"+fb.getSearchData()+
					   "' and cono="+fb.getCono()+" and dbname='"+fb.getDbname()+"' order by dbno desc";
				rs = st.executeQuery(sql1);
			} else if (fb.getSearchList().equals("dbtitle")) {
				/*sql2 = "select data.*, (@rownum:=@rownum+1) num from (select *, (@rownum:=0) rnum from databoard where dbtitle like '%"
						+ fb.getSearchData()
						+ "%' and cono= "
						+ fb.getCono()
						+ " and dbname='"
						+ fb.getDbname()
						+ "')data order by num desc limit "
						+ rowsPerPage
						* (currentPage - 1) + "," + rowsPerPage;*/
				//##
				sql2 = "select * from databoard where dbtitle like '%"+fb.getSearchData()+
						"%' and cono="+fb.getCono()+" and dbname='"+fb.getDbname()+"' order by dbno desc";
				rs = st.executeQuery(sql2);
			} else if (fb.getSearchList().equals("dbcontent")) {
				sql3 = "select data.*, (@rownum:=@rownum+1) num from (select *, (@rownum:=0) rnum from databoard where dbcontent like '%"
						+ fb.getSearchData()
						+ "%' and cono= "
						+ fb.getCono()
						+ " and dbname='"
						+ fb.getDbname()
						+ "')data order by num desc limit "
						+ rowsPerPage
						* (currentPage - 1) + "," + rowsPerPage;
				rs = st.executeQuery(sql3);
			}
			while (rs.next()) {
				
				 
			     rownum -= 1;
			    
				
				DataBoard dboard = new DataBoard();
				dboard.setDbno(rs.getInt(1));
				dboard.setCono(rs.getInt(2));
				dboard.setDbname(rs.getString(3));
				dboard.setMid(rs.getString(4));
				dboard.setDbtitle(rs.getString(5));
				dboard.setDbdate(rs.getString(6));
				dboard.setDbcontent(rs.getString(7));
				dboard.setDbcounter(rs.getInt(8));
				dboard.setDbsfn(rs.getString(9));
				dboard.setDbofn(rs.getString(10));
				dboard.setDbfsize(rs.getInt(11));
				dboard.setDbftype(rs.getString(12));
				dboard.setRownum(rownum);

				dboard.setCommentRows(d.getCommentRows(dboard.getDbno()));

				list.add(dboard);
			     }
			
			rs.close();
			st.close();
			System.out.println("검색된 게시물 수 : " + list.size());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return list;
	}

	// 특정 커뮤니티의 자료실 이름 가져오기
	public String[] getBoardMenus(int cono) {
		Vector<String> v = new Vector<String>();
		String[] menus = null;
		String sql = "select distinct dbname from databoard where cono=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, cono);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				v.add(rs.getString(1));
			}
			menus = new String[v.size()];
			for (int i = 0; i < menus.length; i++) {
				menus[i] = v.get(i);
			}
			rs.close();
			pstmt.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return menus;
	}

	// 자료실 글 조회수 증가
	public boolean incrementCounter(DataBoard db) {
		Connection conn = ConnectionManager.getConnection();
		try {
			Statement st = conn.createStatement();
			st
					.executeUpdate("update databoard set dbcounter=dbcounter+1 where dbno="
							+ db.getDbno());
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
	}	

	// 자료실 메인페이지 최근 목록 가져오기
	public Vector<DataBoard> getTopList(DataBoard db) {
		
		int rownum = getTotalRows(db) + 1;
		 int index = 0;      //모든 행에 1번부터 끝행까지 번호를 임시로 준다
		  long startindex = 0; //보여질 페이지의 첫행의 인덱스
		  long endindex = 0;   //보여질 페이지의 마지막행의 인덱스
		  startindex = (1 - 1) * 1 + 1;
		  endindex = 1 * 5;
		
		
		Vector<DataBoard> v = new Vector<DataBoard>();
		Connection conn = ConnectionManager.getConnection();
		DataCommentDAO d = new DataCommentDAO();
		/*String sql = "select data.*, (@rownum:=@rownum+1) num from "
			  +" (select *, (@rownum:=0) rnum from databoard where cono=? and dbname=?)data order by num desc limit 0,5";*/
		String sql = "select * from databoard where cono=? and dbname=? order by dbno desc";
		try {
			PreparedStatement ps  = conn.prepareStatement(sql);
			ps.setInt(1, db.getCono());
			ps.setString(2, db.getDbname());
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				
				 index += 1;  //@@ 모든 행에 인덱스번호 부여 1~끝까지
			     rownum -= 1;
			     if(index >= 1 && index <= 5){
				
				DataBoard dboard = new DataBoard();
				dboard.setDbno(rs.getInt(1));
				dboard.setCono(rs.getInt(2));
				dboard.setDbname(rs.getString(3));
				dboard.setMid(rs.getString(4));
				dboard.setDbtitle(rs.getString(5));
				dboard.setDbdate(rs.getString(6));
				dboard.setDbcontent(rs.getString(7));
				dboard.setDbcounter(rs.getInt(8));
				dboard.setDbsfn(rs.getString(9));
				dboard.setDbofn(rs.getString(10));
				dboard.setDbfsize(rs.getInt(11));
				dboard.setDbftype(rs.getString(12));
				dboard.setRownum(rownum);
				dboard.setCommentRows(d.getCommentRows(dboard.getDbno()));
				
				v.add(dboard);
			     }
			}
			rs.close();
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}
		return v;
	}
	
	//앞글 가져오기
	public int getPreNum(DataBoard db){
		int preNum = 0;
		Connection conn = ConnectionManager.getConnection();
		String sql = "select max(dbno)dbno from	"
			+" (select dbno from databoard where cono = ? and dbname = ?)data where dbno < ?";
		try{
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, db.getCono());
			ps.setString(2, db.getDbname());
			ps.setInt(3, db.getDbno());
			ResultSet rs = ps.executeQuery();
			if(rs.next()){
				preNum = rs.getInt(1);
			}
			if(preNum==0){
				preNum = db.getDbno();
			}			
			rs.close();
			ps.close();			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}		
		return preNum;
	}
	
	//뒷글 가져오기
	public int getNextNum(DataBoard db){
		int nextNum = 0;
		Connection conn = ConnectionManager.getConnection();
		String sql = "select min(dbno)dbno from	"
			+" (select dbno from databoard where cono = ? and dbname = ?)data where dbno > ?";
		try{
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, db.getCono());
			ps.setString(2, db.getDbname());
			ps.setInt(3, db.getDbno());
			ResultSet rs = ps.executeQuery();
			if(rs.next()){
				nextNum = rs.getInt(1);
			}
			if(nextNum==0){
				nextNum = db.getDbno();
			}			
			rs.close();
			ps.close();			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
				}
			}
		}		
		return nextNum;
	}
	
	//커뮤니티 게시판 이름 수정 하는 메소드
	public void setBoardName(int cono, String dbname, String newname){
		
		String sql = "update databoard set dbname=? where cono=? and dbname=?";
		Connection conn = ConnectionManager.getConnection();
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, newname);
			pstmt.setInt(2, cono);
			pstmt.setString(3, dbname);
			
			pstmt.executeUpdate();
		} catch(Exception e){
			e.printStackTrace();
		} finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
	}
	
	//커뮤니티 게시판 삭제하는 메소드
	public void deleteBoard(int cono, String dbname){
		String sql1 = "delete from datacomment where dbno in (select dbno from databoard where cono=? and dbname=?)";
		String sql2 = "delete from databoard where cono=? and dbname=?";
	
		
		Connection conn = ConnectionManager.getConnection();
		try{
			PreparedStatement pstmt1 = conn.prepareStatement(sql1);
			PreparedStatement pstmt2 = conn.prepareStatement(sql2);
			
			pstmt1.setInt(1, cono);
			pstmt1.setString(2, dbname);
			
			pstmt2.setInt(1, cono);
			pstmt2.setString(2, dbname);
			
			pstmt1.executeUpdate();
			pstmt2.executeUpdate();
			
		} catch(Exception e){
			e.printStackTrace();
		} finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
	}
	
	//특정 게시판 삭제시 저장된 파일명 전부 가져오기 
	public Vector<String> getSavedFileNames(int cono, String dbname){
		Vector<String> v = new Vector<String>();
		Connection conn = ConnectionManager.getConnection();
		String sql="select dbsfn from databoard where cono=? and dbname=?";
		try{
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, cono);
			ps.setString(2, dbname);
			ResultSet rs = ps.executeQuery();
			
			while(rs.next()){
				String savedFileName = new String();
				savedFileName = rs.getString("dbsfn");
				v.add(savedFileName);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return v;
	}
	
	//커뮤니티 게시판 삭제시 저장된 파일명 전부 가져오기 
	public Vector<String> getSavedFileNames(int cono){
		Vector<String> v = new Vector<String>();
		Connection conn = ConnectionManager.getConnection();
		String sql="select dbsfn from databoard where cono=?";
		try{
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, cono);
			ResultSet rs = ps.executeQuery();
			
			while(rs.next()){
				String savedFileName = new String();
				savedFileName = rs.getString("dbsfn");
				v.add(savedFileName);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return v;
	}
	
	//게시판에 new 표시 시간 가져오기
	public Vector<String> getNewDate(){
		Connection conn = ConnectionManager.getConnection();
		Vector<String> newDate= new Vector<String>();		
		//@@ String sql = "select dbdate from databoard where dbdate >=date_add(now(),interval -1 day) and dbdate <=date_add(now(),interval +1 day)";
		String sql = "select dbdate from databoard where dbdate >=date_add(?,interval -1 day) and dbdate <=date_add(?,interval +1 day)";
		try{
			//@@ Statement st = conn.createStatement();
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setTimestamp(1, GetTime.nowTime);
			ps.setTimestamp(2, GetTime.nowTime);
			//@@ ResultSet rs = st.executeQuery(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				String nd = new String();
				nd = rs.getString(1).substring(0, 19);
				newDate.add(nd);				
			}
						
			rs.close();
			ps.close();
			//st.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return newDate;
	}
	

}
